package com.whw.dao.impl;

import com.whw.dao.MyUserDao;
import com.whw.model.MyUser;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by YangZhi on 2016/1/15.
 */
@Repository
public class MyUserDaoImpl extends BaseDaoImpl<MyUser> implements MyUserDao{
    @Override
    public List<MyUser> findByName(String name) {
        String hql = "from MyUser where name like ?";
        return find(hql, "%"+name+"%");
    }

    @Override
    public MyUser findById(int id) {
        String hql = "from MyUser where id = ?";
        return get(hql, id);
    }

    @Override
    public MyUser findByEmail(String email) {
        String hql = "from MyUser where email = ?";
        return get(hql, email);
    }

    @Override
    public void deleteById(int id) {
        delete(findById(id));
    }

    @Override
    public void addMyUser(MyUser myUser) {
         save(myUser);
    }

    @Override
    public void updateMyUserPasswordById(int id, String password) {
      MyUser myuser  =  findById(id );
       myuser.setPassword(password);
        saveOrUpdate(myuser);

    }

    @Override
    public MyUser findByAccountAndPassword(String account, String password) {
        String hql = "from MyUser where account = ? and  password = ?";
        return get(hql,new Object[]{account,password});
    }
}
